package com.hyj.serve.manage.configure.exception;

import com.huitian.mybatis.plus.util.MPUtils;
import com.hyj.serve.manage.configure.common.Result;
import lombok.Data;
import org.springframework.http.HttpStatus;

/**
 * @author HeYuJie
 * @date 2022/3/7
 */
@Data
public class ServiceException extends RuntimeException{
    static final long serialVersionUID = 1L;

    private HttpStatus httpStatus;

    private Result<Object> result = Result.fail("错误").build();

    public ServiceException(){
    }

    public ServiceException(Throwable t){
        super(t);
    }

    public ServiceException(String... message){
        super(MPUtils.str(message));
        result.setMessage(super.getMessage());
    }

    public ServiceException(int code){
        super("系统错误，代码"+ code);
        result.setCode(code);
        result.setMessage(super.getMessage());
    }
    public ServiceException(int code, String... message){
        super(MPUtils.str(message));
        result.setCode(code);
        result.setMessage(MPUtils.str(message));
    }

    public ServiceException(Throwable t, String... message){
        super(MPUtils.str(message), t);
        result.setMessage(super.getMessage());
    }

    public ServiceException(int code, Throwable t){
        super("系统错误，代码"+ code, t);
        result.setCode(code);
        result.setMessage(super.getMessage());
    }
    public ServiceException(int code, Throwable t, String... message){
        super(MPUtils.str(message), t);
        result.setCode(code);
        result.setMessage(super.getMessage());
    }

    public ServiceException httpStatus(HttpStatus httpStatus) {
        this.httpStatus = httpStatus;
        return this;
    }
}
